using System;

using SBPweb.Common.Session;
using SBPweb.Common.Configuration;

using SBPweb.PROvibe.Business.Logic;

namespace SBPweb.PROvibe.Presentation.Controls
{
	/// <summary>
	/// Summary description for MaintainedPage
	/// </summary>
	public class MaintainedPage: System.Web.UI.Page
	{

		#region Public static methods

		public static System.Web.UI.Control FindControlRecursively(System.Web.UI.Control parentControl, string id)
		{
			if (parentControl.ID == id)
				return parentControl;

			foreach (System.Web.UI.Control childControl in parentControl.Controls)
			{
				System.Web.UI.Control foundControl = FindControlRecursively(childControl, id);
				if (foundControl != null)
					return foundControl;
			}
			return null;
		}

		#endregion

		#region Overriden methods

		protected override void OnLoad(EventArgs e)
		{
			SessionHandler.CurrentPage = this.Page.AppRelativeVirtualPath;
			this.MaintainScrollPositionOnPostBack = true;
			base.OnLoad(e);
		}

		protected override void OnPreInit(EventArgs e)
		{
			if (!SessionHandler.IsAvailable)
			{
				Response.Redirect(ConfigurationHandler.VirtualRootDirectory.VirtualPath);
			}
			ThemeManager.MaintainTheme(Page);
			CultureManager.MaintainCulture();

			base.OnPreInit(e);
		}

		#endregion
	}
}